package com.ztgf.shopping.api.client.epg;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.shopping.models.bo.epg.EpgSectionBO;
import com.ztgf.shopping.models.dto.epg.EpgSectionDTO;
import com.ztgf.shopping.models.vo.epg.EpgShopSectionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.shopping.models.service.epg.IEpgShopSectionService;
import com.ztgf.shopping.models.bo.epg.EpgShopSectionBO;
import com.ztgf.shopping.models.dto.epg.EpgShopSectionDTO;

import java.util.List;

/**
 * 店铺频道栏目控制器
 *
 * @author YUE
 * @Date 2020-05-28 18:39:56
 */

@RestController
@RequestMapping("/api/epgShopSection")
@Slf4j
@Api(value = "EpgShopSectionApiController",tags = "店铺频道栏目Api接口")
public class EpgShopSectionApiController {

    @DubboReference
    private IEpgShopSectionService epgShopSectionService;

    @ApiOperation(value = "获取新品推荐",notes = "获取新品推荐")
    @PostMapping("/getNewShopByShopId")
    public Result<EpgShopSectionVO> getNewShopByShopId(Long shopId){
        EpgShopSectionVO epgShopSectionVO = epgShopSectionService.getSectionBySectionType(shopId,"newShop");
        if(null == epgShopSectionVO){
            return new Result<>();
        }
        return new Result<>(epgShopSectionVO);
    }


    @ApiOperation(value = "获取热销",notes = "获取热销")
    @PostMapping("/getHotSellByShopId")
    public Result<EpgShopSectionVO> getHotSellByShopId(Long shopId){
        EpgShopSectionVO epgShopSectionVO = epgShopSectionService.getSectionBySectionType(shopId,"hotSell");
        if(null == epgShopSectionVO){
            return new Result<>();
        }
        return new Result<>(epgShopSectionVO);
    }

    /**
     * 频道栏目列表 根据功能id
     * @param moduleId 功能id
     * @return
     */
    @ApiOperation(value = "频道栏目列表 根据功能id",notes = "频道栏目列表 根据功能id")
    @PostMapping("/getListByModuleId")
    public Result<List<EpgShopSectionDTO>> getListByModuleId(Long moduleId){
        EpgShopSectionBO epgShopSectionBO = new EpgShopSectionBO();
        epgShopSectionBO.setModuleId(moduleId);
        List<EpgShopSectionDTO> epgSectionDTOList = epgShopSectionService.getBySelectShopSectionInfoNoPage(epgShopSectionBO);
        return new Result<>(epgSectionDTOList);
    }



    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<EpgShopSectionDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        EpgShopSectionDTO dto = epgShopSectionService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "店铺频道栏目列表",notes = "店铺频道栏目列表")
    @PostMapping("/querySelectList")
    public Result<List<EpgShopSectionDTO>> querySelectList(EpgShopSectionBO bo){
        if(null == bo)
            return new Result<>(CodeEnum.FAIL_100002 );
        List<EpgShopSectionDTO> epgShopSectionDTOList = epgShopSectionService.getBySelectShopSectionInfoNoPage(bo);

        return new Result<>(epgShopSectionDTOList);
    }
}
